
#include <metal_stdlib>
using namespace metal;

struct CHVertex {
    float4 position [[position]];
    float2 textureCoordinate;
};

struct CHVertexIn {
    float2 position;
    float2 textureCoordinate;
};

// Vertex Function
vertex CHVertex vertextShader(uint vertexID [[vertex_id]],
                              constant CHVertexIn *vertexArray [[buffer(0)]],
                              constant float2 *viewPortSizePointer [[buffer(1)]]
                              )
{
    CHVertex out;
    CHVertexIn in = vertexArray[vertexID];
    float2 pixelSpacePosition = in.position.xy;
    float2 viewportSize = float2(*viewPortSizePointer);
    out.position = float4(0.0, 0.0, 0.0, 1.0);
    out.position.xy = pixelSpacePosition / (viewportSize / 2.0);
    out.textureCoordinate = in.textureCoordinate;
    return out;
}

// Fragment Function
fragment float4 samplingShader(CHVertex in [[stage_in]],
                               texture2d<half> colorTexture [[ texture(0) ]]
                               ) {
    constexpr sampler texureSampler(mag_filter::linear,
                                    min_filter::linear);
    const half4 colorSample = colorTexture.sample(texureSampler, in.textureCoordinate);
    return float4(colorSample);
}
